import 'package:flutter/material.dart';
import 'package:local_coffee/components/c_appbar/custom_appbar.dart';
import 'package:local_coffee/components/c_button/index.dart';
import 'package:local_coffee/components/hex.dart';
import 'package:local_coffee/components/icon.dart';
import 'package:local_coffee/components/rgba.dart';
import 'package:local_coffee/routes/index.dart';
import 'package:local_coffee/utils/global.dart';

class OrderDetail extends StatefulWidget {
  
  final Map args;

  OrderDetail({
    this.args
  });

  _OrderDetailState createState() => _OrderDetailState();
}

class _OrderDetailState extends State<OrderDetail> {
  
  static Map args;

  @override
  void initState() {
    super.initState();

    setState(() {
      args = widget.args;
    });
  }

  /// 下单成功 status = 1
  buySuccess() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 30),
      color: HEX.hexfff,
      child: Column(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                '下单成功',
                style: TextStyle(
                  color: RGBA.rgba383838,
                  fontSize: 18,
                  fontWeight: FontWeight.bold
                ),
              ),
              Container(
                margin: EdgeInsets.only(left: 10),
                width: 55,
                height: 16,
                decoration: BoxDecoration(
                  border: Border.all(
                    color: RGBA.rgbad9d9d9,
                  ),
                  borderRadius: BorderRadius.circular(4)
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    icon0xe626(
                      color: RGBA.rgba30649d,
                      size: 10
                    ),
                    Text(
                      '慢必赔',
                      style: TextStyle(
                        color: RGBA.rgba505050,
                        fontSize: 10
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
          Container(
            margin: EdgeInsets.only(top: 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  '预计',
                  style: TextStyle(
                    color: RGBA.rgba383838,
                    fontSize: 12
                  ),
                ),
                Text(
                  '15:15',
                  style: TextStyle(
                    color: RGBA.rgba94c4ec,
                    fontSize: 12
                  ),
                ),
                Text(
                  '送达，请耐心等待 coffee 来临！',
                  style: TextStyle(
                    color: RGBA.rgba383838,
                    fontSize: 12
                  ),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                CButton.normal(
                  child: Text(
                    '取消下单',
                    style: TextStyle(
                      fontSize: 14
                    ),
                  ),
                  width: 105,
                  height: 32,
                  plain: true,
                  color: RGBA.rgba383838,
                  borderColor: RGBA.rgbad9d9d9,
                  onPressed: () => {}
                ),
                Container(
                  margin: EdgeInsets.only(left: 10),
                  child: CButton.normal(
                    child: Text('取餐码'),
                    width: 105,
                    height: 32,
                    plain: true,
                    color: RGBA.rgba88afd5,
                    borderColor: RGBA.rgba88afd5,
                    onPressed: () => {}
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  /// 待付款
  waitPayment() {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 30),
      color: HEX.hexfff,
      child: Column(
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                '待付款',
                style: TextStyle(
                  color: RGBA.rgba383838,
                  fontSize: 18,
                  fontWeight: FontWeight.bold
                ),
              )
            ],
          ),
          Container(
            margin: EdgeInsets.only(top: 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  '请在',
                  style: TextStyle(
                    color: RGBA.rgba383838,
                    fontSize: 12
                  ),
                ),
                Text(
                  '15:15',
                  style: TextStyle(
                    color: RGBA.rgba94c4ec,
                    fontSize: 12
                  ),
                ),
                Text(
                  '内完成支付，过时订单将会取消',
                  style: TextStyle(
                    color: RGBA.rgba383838,
                    fontSize: 12
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 15),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                // AButton.bigButton('取消订单',
                //     width: 105,
                //     height: 32,
                //     fontSize: 14,
                //     fontWeight: FontWeight.bold,
                //     bgColor: Colors.transparent,
                //     color: rgba(56, 56, 56, 1),
                //     border: Border.all(color: rgba(217, 217, 217, 1)),
                // ),
                // Container(
                //   margin: EdgeInsets.only(left: 10),
                //   child: AButton.bigButton('去支付',
                //       width: 105,
                //       height: 32,
                //       fontSize: 14,
                //       bgColor: Colors.transparent,
                //       color: rgba(255, 129, 2, 1),
                //       border: Border.all(color: rgba(255, 129, 2, 1)),
                //   ),
                // ),
              ],
            ),
          )
        ],
      ),
    );
  }

  /// 返回对应的 page
  returnPage() {
    switch (args['status']) {
      case 1:
        return buySuccess();
      case 2:
        return waitPayment();
      default:
        return Container();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: customAppBar(
        title: '订单详情',
        context: context,
        actions: <Widget>[
          Container(
            padding: EdgeInsets.only(right: 20),
            child: Icon(
              IconData(
                0xe625,
                fontFamily: 'iconfont'
              ),
              size: 18,
              color: RGBA.rgba94c4ec,
            ),
          )
        ],
      ),
      body: SingleChildScrollView(
        child: SafeArea(
          child: Column(
            children: <Widget>[
              // module1
              returnPage(),
              // module2
              Container(
                padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
                margin: EdgeInsets.only(top: 10),
                color: HEX.hexfff,
                child: Column(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.only(bottom: 12),
                      decoration: BoxDecoration(
                        border: G.borderBottom()
                      ),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            '外卖订单:2020032015081231311',
                            style: TextStyle(
                              color: RGBA.rgba808080,
                              fontSize: 13
                            ),
                          ),
                          Text(
                            '2020-03-20 15:08',
                            style: TextStyle(
                              color: RGBA.rgba808080,
                              fontSize: 13
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 18),
                      child: Column(
                        children: <Widget>[
                          Container(
                            margin: EdgeInsets.only(bottom: 12),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: <Widget>[
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Container(
                                      child: Text(
                                        '拿铁',
                                        style: TextStyle(
                                          color: RGBA.rgba383838,
                                          fontSize: 15,
                                          fontWeight: FontWeight.bold
                                        ),
                                      ),
                                    ),
                                    Container(
                                      child: Text(
                                        'asda',
                                        style: TextStyle(
                                          color: RGBA.rgba383838,
                                          fontSize: 10,
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                                Row(
                                  children: <Widget>[
                                    Text(
                                      'x3',
                                      style: TextStyle(
                                        color: RGBA.rgba505050,
                                        fontSize: 13
                                      ),
                                    ),
                                    Container(
                                      margin: EdgeInsets.only(left: 80),
                                      child: Text(
                                        '￥ 20',
                                        style: TextStyle(
                                          color: RGBA.rgba383838,
                                          fontSize: 14,
                                          fontWeight: FontWeight.bold
                                        ),
                                      ),
                                    )
                                  ],
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(vertical: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            '配送费',
                            style: TextStyle(
                              color: RGBA.rgba383838,
                              fontSize: 14
                            ),
                          ),
                          Text(
                            '￥ 6',
                            style: TextStyle(
                              color: RGBA.rgba383838,
                              fontSize: 14,
                              fontWeight: FontWeight.bold
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      decoration: BoxDecoration(
                        border: G.borderBottom()
                      ),
                      padding: EdgeInsets.symmetric(vertical: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            '使用咖啡钱包',
                            style: TextStyle(
                              color: RGBA.rgba94c4ec,
                              fontSize: 14
                            ),
                          ),
                          Text(
                            '-￥ 21',
                            style: TextStyle(
                              color: RGBA.rgba94c4ec,
                              fontSize: 14,
                              fontWeight: FontWeight.bold
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      padding: EdgeInsets.symmetric(vertical: 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Text(
                            '共 1 件商品',
                            style: TextStyle(
                              color: RGBA.rgba383838,
                              fontSize: 14
                            ),
                          ),
                          Row(
                            children: <Widget>[
                              Text(
                                '实付',
                                style: TextStyle(
                                  color: RGBA.rgba383838,
                                  fontSize: 14
                                ),
                              ),
                              Text(
                                '￥ 21',
                                style: TextStyle(
                                  color: RGBA.rgba383838,
                                  fontSize: 18,
                                  fontWeight: FontWeight.bold
                                ),
                              ),
                            ],
                          )
                        ],
                      ),
                    )
                  ],
                ),
              ),
              // module3
              Container(
                margin: EdgeInsets.only(top: 10),
                color: HEX.hexfff,
                padding: EdgeInsets.symmetric(vertical: 12, horizontal: 15),
                child: Column(
                  children: <Widget>[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(
                          '收货地址',
                          style: TextStyle(
                            color: RGBA.rgba383838,
                            fontSize: 14
                          ),
                        ),
                        Text(
                          'xx区xx路xx号xxx幢xxx层Xxx号',
                          style: TextStyle(
                            color: RGBA.rgba808080,
                            fontSize: 13
                          ),
                        ),
                      ],
                    ),
                    Container(
                      margin: EdgeInsets.only(top: 5),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                          Text(
                            'xx 先生',
                            style: TextStyle(
                              color: RGBA.rgba808080,
                              fontSize: 13
                            ),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ),
              // module4
              Container(
                margin: EdgeInsets.only(top: 10),
                child: Image.asset(
                  P.order2,
                  height: 60,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}